package com.jltx.zeus.view

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.jltx.zeus.viewmodel.ActionEventObserver
import kotlinx.coroutines.CoroutineScope

/**
 * @author jltxseo
 *         Created by junlintianxia on 2020/05/08.
 */
abstract class BaseFragment : Fragment(), ActionEventObserver {
    override val viewModelScope: CoroutineScope
        get() = lifecycleScope

    override val lContext: Context?
        get() = activity

    override val lLifecycleOwner: LifecycleOwner
        get() = this

    protected abstract val rootLayoutId: Int

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(rootLayoutId, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView(savedInstanceState)
        initListener()
        initData()
    }

    override fun showLoading(msg: String) {

    }

    override fun dismissLoading() {

    }

    override fun finishView() {
        activity?.finish()
    }

    protected open fun initView(savedInstanceState: Bundle?) {}

    protected open fun initData() {}

    protected open fun initListener() {}
}